﻿using System;

namespace nhCore
{

    /// <summary>
    /// 环境基本要素，基本成员对应Configs表字段
    /// </summary>
    public class ElementConfig
    {
        /// <summary>
        /// 生成要素对象
        /// </summary>
        /// <param name="display">要素名称</param>
        /// <param name="unit">要素单位</param>
        /// <param name="digits">小数点位数，float时小数点只用于显示</param>
        /// <param name="index"></param>
        public ElementConfig(string display, string unit, int digits, short index)
        {
            Display = display;
            Unit = unit;
            Digits = digits;
            Index = index;
        }

        public ElementConfig() { }

        #region 对应Config数据表
        /// <summary>
        /// 数据显示名称
        /// </summary>
        public string Display { get; set; }

        /// <summary>
        /// 单位
        /// </summary>
        public string Unit { get; set; }

        /// <summary>
        /// 寄存器地址
        /// </summary>
        public Int16 Index { get; set; }

        /// <summary>
        /// 小数位
        /// </summary>
        public int Digits { get; set; }

        /// <summary>
        /// 数据类型，如float，Int32，默认Int16
        /// </summary>
        public Type DataType { get; set; } = typeof(Int16);

        /// <summary>
        /// 要素类型，如FengSu，FengXiang，JiangYu，ZhengFa，
        /// </summary>
        public string Type { get; set; } = string.Empty;

        /// <summary>
        /// 统计方式
        /// </summary>
        public string Statistics { get; set; }

        /// <summary>
        /// 最大值，超过时报警
        /// </summary>
        public double? Max { get; set; }

        /// <summary>
        /// 最小值，低于时报警
        /// </summary>
        public double? Min { get; set; }
        #endregion

        /// <summary>
        /// 要素标题+值+单位
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return $"{Display}";
        }
    }
}
